package com.jike.jkgame.data;

import com.jike.jkgame.Utilis;

public class RewardItem {
	public int id;
	public byte possibility;
	public byte type;

	/*
	 * [id, possibility]
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "[" + String.valueOf(id) + "," + String.valueOf(possibility)
				+ "," + String.valueOf(type) + "]";
	}

	public static RewardItem fromString(String str) {

		if (str.startsWith("[") && str.endsWith("]")) {
			String subStr = str.substring(1, str.length() - 1);
			RewardItem item = new RewardItem();
			String[] subs = subStr.split(",");
			item.id = Integer.valueOf(subs[0]);
			item.possibility = Byte.valueOf(subs[1]);
			item.type = Byte.valueOf(subs[2]);

			return item;
		}

		return null;
	}

	public static RewardItem[] stringToRewardItemArray(String str) {

		if (str == null) {
			return null;
		}

		String[] itemStrs = str.split(Utilis.SEPERATOR);
		RewardItem[] items = new RewardItem[itemStrs.length];
		for (int i = 0; i < itemStrs.length; ++i) {
			items[i] = RewardItem.fromString(itemStrs[i]);
		}

		return items;

	}
}
